﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZLB_Model.PDF;
using ZLB_Service.Hospital_Config;
using ZLB_Unility.Common;

namespace ZLB_Service.Basic
{
    public class BaseService
    {
        public string ConvertTime(string date, string format = "yyyy-MM-dd HH:mm:ss")
        {
            if (string.IsNullOrEmpty(date))
                return string.Empty;

            DateTime dt = DateTime.Now;

            if(!DateTime.TryParse(date,out dt))
                dt = DateTime.Now;

            return dt.ToString(format);
        }

        public string ConvertAge(string age,string idcard)
        {
            if (!string.IsNullOrEmpty(age))
                return age;

            string ageStr = string.Empty;
            if (ToolHelper.IsIDCard(idcard))
                ageStr = ToolHelper.GetAgeByBirthdate(DateTime.Parse(ToolHelper.GetBirthday(idcard))).ToString();

            return ageStr;
        }

        public string GetXmlHeader(string tradecode)
        {
            XmlHeader XmlHeader = new XmlHeader();
            XmlHeader.organization_id = HospiatlManager.organization_id;
            XmlHeader.tradecode = tradecode; // 接口编号
            XmlHeader.token = HospiatlManager.token;
            XmlHeader.request_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            XmlHeader.operator_code = "001";
            XmlHeader.operator_name = HospiatlManager.hospital_name;
            XmlHeader.client_ip = HospiatlManager.ip;
            XmlHeader.client_macaddress = HospiatlManager.mac;

            return JsonXmlUtils.XmlSerialize(XmlHeader);
        }

    }
}
